package uit.comstore.model.blo;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import uit.comstore.model.entity.OrderDetail;
import uit.comstore.utils.HibernateSessionFactory;

public class OrderDetailBLO {
	@SuppressWarnings("unchecked")
	public List<OrderDetail> list() {
		List<OrderDetail> orderDetails = null;
		Session session = HibernateSessionFactory.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		orderDetails = (List<OrderDetail>) session.createQuery("from OrderDetail").list();
		session.getTransaction().commit();
		return orderDetails;
	}
	
	@SuppressWarnings("unchecked")
	public List<OrderDetail> getById(Long id){
		List<OrderDetail> orderDetails = null;
		Session session = HibernateSessionFactory.getSessionFactory().getCurrentSession();	
		session.beginTransaction();
		//orderDetails = (List<OrderDetail>) session.createQuery("from OrderDetail where").list();
		Query query = session.createQuery("from OrderDetail where order.id = :value");
		query.setParameter("value", id);
		orderDetails = query.list();
		session.getTransaction().commit();
		return orderDetails;
	}
}
